package com.taplinker.client.im.rpc;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import com.taplinker.client.im.activity.IMQueueActivity;
import com.taplinker.client.im.domain.ImDataCenter;
import com.taplinker.client.im.protocol.TapLinkerConversation;
import com.taplinker.client.im.rpc.body.Cmd012Req;
import com.taplinker.core.rpc.Result;

public class Cmd012 extends SimpleSocketCommand<Cmd012Req> {

	private Context context;

	public Cmd012(String conversationId, String reason, Context context) {
		body = new Cmd012Req();
		body.setConversationId(conversationId);
		body.setReason(reason);
		this.context = context;
	}

	public Cmd012(String conversationId, Context context) {
		body = new Cmd012Req();
		body.setConversationId(conversationId);
		this.context = context;
	}

	@Override
	public void yes(Result result) {

		super.yes(result);
		TapLinkerConversation con = ImDataCenter.getInstance()
				.removeConversationByIdFromPri(body.getConversationId());
		con.setStatus("FINISH");
		ImDataCenter.getInstance().noticeListener(body.getConversationId());
		Intent intent = new Intent(context, IMQueueActivity.class);
		context.startActivity(intent);
		
	}

	@Override
	public void no(Result result) {
		super.no(result);
		if (((IMMessageResponse) result.object).getErrorCode() == 408) {
			new AlertDialog.Builder(context)
					.setTitle("提示：")
					.setMessage("该客户未移交！")
					.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {

								}
							}).show();
		}
	}

	@Override
	protected String getCommand() {
		return "012";
	}
}
